<?php

namespace app\api\controller;

use think\Controller;

class Information extends Controller
{
    //最新资讯
    public function information()
    {
        $information = model('common/Information')
            -> where('status',1)
            -> field('id,img,title,content')
            -> order('create_time','desc')
            -> find();
        if ($information){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$information]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败']);
        }
    }

    //资讯列表
    public function information_list()
    {
        $information = model('common/Information')
            -> where('status',1)
            -> field('id,img,title,content')
            -> order('create_time','desc')
            -> select();
        if ($information){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$information]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败']);
        }
    }

    //资讯详情
    public function information_content()
    {
        $information = model('common/Information')
            -> where('id',input('id'))
            -> field('title,author,num,create_time,content')
            -> find();
        $information -> setInc('num');
        if ($information){
            return json(['code'=>100,'msg'=>'请求成功','data'=>$information]);
        } else {
            return json(['code'=>404,'msg'=>'请求失败']);
        }
    }


}
